See if I can make QtWebKit (Linux) and QtWebEngine (everywhere else) coexist.
authorRobert Lipe <robertlipe@gpsbabel.org>
Sat, 31 Dec 2016 23:28:10 +0000 (17:28 -0600)
committerRobert Lipe <robertlipe@gpsbabel.org>
Sat, 31 Dec 2016 23:28:10 +0000 (17:28 -0600)
gui/app.pro
gui/map.cc
gui/map.h

index 930cfe0f704f64f99adc7ab234fbb0d4e315836b..c5125072c610ec1aeca0eedf04eedb7a268996a2 100755 (executable)
@@ -15,11 +15,12 @@ QT += core \
       gui \
       network \
       xml \
-      webkit
 
-greaterThan(QT_MAJOR_VERSION, 4) {
-  QT += widgets \
-        webkitwidgets
+greaterThan(QT_MINOR_VERSION, 5) {
+  QT += webenginewidgets
+  DEFINES += HAVE_WEBENGINE
+} else {
+  QT += webkit webkitwidgets 
 }
 
 unix:DESTDIR = objects
index 32843764a141ebd2e346da06676187ad8ee461e7..23cee4d703134207de8933287c5879154d7b124d 100644 (file)
 //  USA
 //
 //------------------------------------------------------------------------
+#include "map.h"
+
 #include <QNetworkRequest>
 #include <QMessageBox>
 #include <QNetworkAccessManager>
+#if HAVE_WEBENGINE
+#include <QWebEngineView>
+#include <QWebChannel>
+#else
 #include <QWebFrame>
 #include <QWebPage>
+#endif
 #include <QApplication>
 #include <QCursor>
 #include <QFile>
 
 #include <math.h>
-#include "map.h"
 #include "appname.h"
 #include "dpencode.h"
 
@@ -47,7 +53,11 @@ static QString stripDoubleQuotes(const QString s) {
 //------------------------------------------------------------------------
 Map::Map(QWidget *parent,
         const Gpx  &gpx, QPlainTextEdit *te):
+#if HAVE_WEBENGINE
+    QWebEngineView(parent),
+#else
     QWebView(parent),
+#endif
     gpx_(gpx),
     mapPresent_(false),
     busyCursor_(false),
@@ -125,7 +135,14 @@ static QString fmtLatLng(const LatLng &l) {
 void Map::showGpxData()
 {
   MarkerClicker *mclicker = new MarkerClicker(this);
+#if HAVE_WEBENGINE
+  QWebChannel* channel = new QWebChannel(this);
+  this->page()->setWebChannel(channel);
+  channel->registerObject(QStringLiteral("mclicker"), mclicker);
+//  this->addToJavaScriptWindowObject("mclicker", mclicker);
+#else
   this->page()->mainFrame()->addToJavaScriptWindowObject("mclicker", mclicker);
+#endif
   connect(mclicker, SIGNAL(markerClicked(int, int )), this, SLOT(markerClicked(int, int)));
   connect(mclicker, SIGNAL(logTime(const QString &)), this, SLOT(logTimeX(const QString &)));
 
@@ -385,7 +402,11 @@ void Map::panTo(const LatLng &loc)
 //------------------------------------------------------------------------
 void Map::resizeEvent ( QResizeEvent * ev)
 {
+#if HAVE_WEBENGINE
+  QWebEngineView::resizeEvent(ev);
+#else
   QWebView::resizeEvent(ev);
+#endif
   if (mapPresent_)
     evaluateJS(QString("map.checkResize();"));
 }
@@ -429,7 +450,11 @@ void Map::frameRoute(int i)
 //------------------------------------------------------------------------
 void Map::evaluateJS(const QString &s, bool upd)
 {
+#if HAVE_WEBENGINE
+  this->page()->runJavaScript(s);
+#else
   this->page()->mainFrame()->evaluateJavaScript(s);
+#endif
   if (upd) {
     this->update();
   }
index e729a1fd2d4ae6f6bc3e12dab356e7841c81d1f2..baa57e915f5e320240d3c77aa7f8de94167a2202 100644 (file)
--- a/gui/map.h
+++ b/gui/map.h
 //------------------------------------------------------------------------
 #ifndef MAP_H
 #define MAP_H
-
+#if HAVE_WEBENGINE
+#include <QWebEngineView>
+#else
 #include <QWebView>
+#endif
 #include <QPlainTextEdit>
 #include <QTime>
 #include "gpx.h"
@@ -49,7 +52,11 @@ signals:
 
 
 
+#if HAVE_WEBENGINE
+class Map : public QWebEngineView
+#else
 class Map : public QWebView
+#endif
 {
   Q_OBJECT
     public: